448. 找到所有数组中消失的数字
为保证权益,题目请参考 448. 找到所有数组中消失的数字(From LeetCode).
解决方案1
Python
python
from typing import List
class Solution:
def findDisappearedNumbers(self, nums: List[int]) -> List[int]:
for i in range(len(nums)):
pos = abs(nums[i])
if nums[pos-1] > 0:
nums[pos-1] = - nums[pos-1]
ans = []
for i in range(len(nums)):
if nums[i] > 0:
ans.append(i+1)
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16